import re

# re.S  re.I  re.M
# 正则修饰符用于对正则表达式的说明
# '.'表示出了换行以外的任意字符
print(re.search(r'a.*b', 'asd\nnotebook'))  # None
print(re.search(r'a.*b', 'asd\nnotebook', re.S))  # 使'.'对换行可以匹配
print(re.search(r'a', 'THERE IS A APPLE', re.I))  # 忽略大小写

# \w: 表示字母、数字、下划线   +: 表示出现一次以上  $: 表示以指定内容结尾
a = re.findall(r'\w+$', 'make anchors\nlook\nfor newline')
b = re.findall(r'\w+$', 'make anchors\nlook\nfor newline', re.M)  # 将每一行看做一个字符串
"""
make anchors
look
for newline
"""
print(a)  # ['newline']
print(b)  # ['anchors', 'look', 'newline']

r"""
    Some of the functions in this module takes flags as optional parameters:
        A  ASCII       For string patterns, make \w, \W, \b, \B, \d, \D
                       match the corresponding ASCII character categories
                       (rather than the whole Unicode categories, which is the
                       default).
                       For bytes patterns, this flag is the only available
                       behaviour and needn't be specified.
        I  IGNORECASE  Perform case-insensitive matching. 忽略大小写
        L  LOCALE      Make \w, \W, \b, \B, dependent on the current locale.
        M  MULTILINE   "^" matches the beginning of lines (after a newline)
                       as well as the string.
                       "$" matches the end of lines (before a newline) as well
                       as the end of the string.
        S  DOTALL      "." matches any character at all, including the newline.
        X  VERBOSE     Ignore whitespace and comments for nicer looking RE's.
        U  UNICODE     For compatibility only. Ignored for string patterns (it
                       is the default), and forbidden for bytes patterns.
    
    This module also defines an exception 'error'.
    
    
    ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
    IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
    LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
    UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
    MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
    DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
    VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
"""
